import React, { Component } from 'react';
import moment from 'moment';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { saveAsJson } from '@/utils/utils';
import { ArticleType } from '@/domains/article';
import Editor from '@/components/Editor';

interface ArticleEditorProps {}

interface ArticleEditorState {}

class ArticleEditor extends Component<ArticleEditorProps, ArticleEditorState> {
  onSave = (res: ArticleType) => {
    const time = moment().format('YYYY-MM-DD HH:mm:ss');
    saveAsJson(JSON.stringify({ ...res, time }), time);
    const { title, summary, tags } = res;
    saveAsJson(JSON.stringify({ title, summary, tags, time }), 'index');
  };

  render() {
    return (
      <PageHeaderWrapper title={false}>
        <Editor onSave={this.onSave} />
      </PageHeaderWrapper>
    );
  }
}

export default ArticleEditor;
